package com.wenlin.myproduction.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.bean.NumberCard;
import com.wenlin.myproduction.util.TypeData;
import com.wenlin.myproduction.util.TypeDataNames;
import com.wenlin.myproduction.util.UI;

import org.greenrobot.eventbus.EventBus;

import me.drakeet.multitype.ItemViewBinder;

/**
 * @author 文琳
 * @time 2020/9/1 14:07
 * @desc
 */
public class NumberCardBinder extends ItemViewBinder<NumberCard, NumberCardBinder.NumberCardHolder> {

    @NonNull
    @Override
    protected NumberCardHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new NumberCardHolder(inflater.inflate(R.layout.item_number_card, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull NumberCardHolder holder, @NonNull NumberCard bean) {
        UI.setText(holder.tv, bean.getStr());
        UI.setText(holder.tvPosition, bean.getPosition() + 1);
        UI.setTextColor(holder.tv, bean.isFinish() ? R.color.myGray3 : R.color.myWhite);
        boolean hideMask = bean.isShow() || bean.isFinish();
        UI.setVisibleInvisible(holder.tvPosition, !hideMask);
        holder.itemView.setOnClickListener(v -> EventBus.getDefault().post(new TypeData<>(TypeDataNames.clickNumberCard, bean)));
    }

    static class NumberCardHolder extends RecyclerView.ViewHolder {
        TextView tv, tvPosition;

        public NumberCardHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv);
            tvPosition = itemView.findViewById(R.id.tv_position);
        }
    }
}
